import { defineStore } from "pinia";
import { ref } from "vue";
import { queryHotArticleList, queryArticleList } from "@/api/article.api";
import { ArticleList } from "@/types/article";
/**
 * 文章状态
 */
export const useArticleStore = defineStore("articleStore", () => {
  // 热门文章
  const hotArticleList = ref<ArticleList>([]);
  const getHotArticleList = async () => {
    const res = await queryHotArticleList();
    if (res.code === 200) {
      hotArticleList.value = res.data || [];
    }
  };
  // 置顶文章
  const topArticleList = ref<ArticleList>([]);
  const getTopArticleList = async () => {
    const params = {
      pageNo: 1,
      pageSize: 10,
    };
    const res = await queryArticleList(params);
    if (res.code === 200) {
      topArticleList.value = res.data ? res.data.rows : [];
    }
  };
  return {
    hotArticleList,
    getHotArticleList,
    topArticleList,
    getTopArticleList,
  };
});
